# -*- coding: utf-8 -*-
# @Time        :2024/10/24 下午3:09
# @Author      :文刀水寿
# @File        : 读取mysql.py
"""
 @Description :综合案例，读取文件，写入MYSQL数据库
"""
import json

from pymysql import Connection

conn = Connection(
    host='localhost',
    port=3306,
    user='root',
    password='1028',
    autocommit=True
)
cursor = conn.cursor()
conn.select_db("py_sql")
cursor.execute("select cast(order_date as char(20)) as date,order_id,money,province from orders")
results = cursor.fetchall()
f = open("D:/输出数据库.txt", "a", encoding='UTF-8')
f.write("{")
for x in results:
    json_str = json.dumps(x, ensure_ascii=False)
    f.write(json_str)
f.write("}")
f.close()
conn.close()
